The complete program is given below.
This program is suitable for copying into a program editor, compiling and running in the usual way. Animal brains, such as humans have, learn best when they see things happen. Run the program. See things happen.
import java.io.*; // User enters integer N. The program calculates N factorial. // class factorial { public static void main (String[] args ) throws IOException { BufferedReader userin = new BufferedReader (new InputStreamReader(System.in)); String inputData; long N, fact = 1; System.out.println( "Enter N:" ); inputData = userin.readLine(); N = Integer.parseInt( inputData ); if ( N >= 0 ) { while ( N > 1 ) { fact = fact * N; N = N - 1; } System.out.println( "factorial is " + fact ); } else { System.out.println("N must be zero or greater"); } } }